//
//  ViewController.swift
//  JWGuideMarkerManager
//
//  Created by linjw on 05/01/2023.
//  Copyright (c) 2023 linjw. All rights reserved.
//

import UIKit
import JWGuideMarkerManager
import SnapKit

class ViewController: UIViewController {

    var list: [JWGuideMarkerData] = []
    var guideController: JWGuideMarkerManager?
    
    /// 提交按钮
    lazy var submitButton: UIButton = {
        let it = UIButton()
        it.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        it.setTitleColor(.black, for: .normal)
        it.setTitle("显示", for: .normal)
        it.setImage(nil, for: .normal)
        it.setBackgroundImage(nil, for: .normal)
        
        it.addTarget(self, action: #selector(tapSubmitButton(_:)), for: .touchUpInside)
        
        it.contentVerticalAlignment = .center
        it.contentHorizontalAlignment = .center
        
        return it
    }()

    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(submitButton)
        submitButton.snp.makeConstraints {
            $0.left.right.equalTo(0)
            $0.height.equalTo(50)
            $0.bottom.equalTo(-50)
        }
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    
    
    @objc func tapNextButton(_ sender: UIButton) {
        self.guideController?.nextCoachMarker()

    }
        @objc func tapSubmitButton(_ sender: UIButton) {
        guideController = JWGuideMarkerManager(parentView: self.view)
        guideController?.dataSource = self
        
        list = [
            JWGuideMarkerData(frame: CGRect(x: 100, y: 100, width: 50, height: 50), radius: 25.0, animationStyle: .scale),
            JWGuideMarkerData(frame: CGRect(x: 100, y: 200, width: 200, height: 50), animationStyle: .move),
            JWGuideMarkerData(frame: CGRect(x: 100, y: 300, width: 200, height: 50), radius: 25, animationStyle: .move),
        ]
        
        guideController?.showGuideMarker()
    }
    
}

extension ViewController: JWGuideMarkerManagerDataSource {
    
    func guideMarkerNumbers(_ guideMarker: JWGuideMarkerManager) -> Int {
        return list.count
    }
    
    func guideMarker(_ guideMarker: JWGuideMarkerManager, markerForItemAtIndex index: Int) -> JWGuideMarkerData {
        return list[index]
    }
    
    func guideMarker(_ guideMarker: JWGuideMarkerManager, viewForItemAtIndex index: Int) -> UIView {
        let it = UIButton(frame: self.view.bounds)
        it.backgroundColor = .black.withAlphaComponent(0.7)
        it.addTarget(self, action: #selector(tapNextButton(_:)), for: .touchUpInside)
        return it
    }
    
}

